Source for file containers.class.php

Documentation is available at containers.class.php

  1. <?php
  2.  
  3. class mosContainer extends mosTableEntry {
  4.     /** @var int ID for container record in database */
  5.     public $id = 0;
  6.     /** @var int Ordering */
  7.     public $ordering = 0;
  8.     /** @var string Window title */
  9.     public $windowtitle = '';
  10.     /** @var string Key words */
  11.     public $keywords = '';
  12.     /** @var int ID of parent container in database if a folder */
  13.     public $parentid = 0;
  14.     /** @var string Name of container */
  15.     public $name = '';
  16.     /** @var string Container description */
  17.     public $description='';
  18.     /** @var bool Is the container published? */
  19.     public $published=false;
  20.     /** @var string Icon - not sure how this is used */
  21.     public $icon='';
  22.     /** @var bool Has all the data been loaded (rather than just the basics) */
  23.     protected $loaded = 0;
  24.     /** @var array Child containers */
  25.     protected $children = array();
  26.     /** @var bool When true, the item is marked as trash */
  27.     protected $isTrash = false;
  28.  
  29.     function tableName ({
  30.         return '#__containers';
  31.     }
  32.  
  33.     function notSQL ({
  34.         return array ('id''loaded''children''database');
  35.     }
  36.  
  37.     function load ({
  38.         $database mamboDatabase::getInstance();
  39.         if ($this->loaded == AND $this->id{
  40.             $database->setQuery("SELECT * FROM #__containers WHERE id=$this->id");
  41.             $database->loadObject($this);
  42.             $this->loaded = 1;
  43.         }
  44.     }
  45.  
  46.     function saveValues ({
  47.         $database mamboDatabase::getInstance();
  48.         $this->prepareValues();
  49.         if ($this->id == 0$database->doSQL($this->insertSQL());
  50.         else $database->doSQL($this->updateSQL());
  51.     }
  52.  
  53.     function trash ({
  54.         $this->isTrash = true;
  55.     }
  56.  
  57.     function isTrash ({
  58.         return $this->isTrash;
  59.     }
  60.  
  61.     function addChild ($id{
  62.         $this->children[$id;
  63.     }
  64.  
  65.     function deleteAll ({
  66.         $folders $this->getChildren(false);
  67.         foreach ($folders as $folder$folder->deleteAll ();
  68. //      Need to delete things that are registered with this
  69.         $this->trash();
  70.     }
  71.  
  72.     function setMetaData ({
  73.         $mainframe mosMainFrame::getInstance();
  74.         $mainframe->prependMetaTag('description'strip_tags($this->name));
  75.         if ($this->keywords$mainframe->prependMetaTag('keywords'$this->keywords);
  76.         else $mainframe->prependMetaTag('keywords'$this->name);
  77.     }
  78.  
  79.     function isCategory ({
  80.         if ($this->parentid == 0return true;
  81.         else return false;
  82.     }
  83.  
  84.     function getCategoryName ($showself=false{
  85.         $category $this->getCategory();
  86.         if ($this->parentid OR $showselfreturn $category->name;
  87.         return '*';
  88.     }
  89.  
  90.     function getCategory ({
  91.         $container =$this;
  92.         while ($container->parentid$container =$container->getParent();
  93.         return $container;
  94.     }
  95.  
  96.     function getFamilyNames ($include=false{
  97.         $names $include '/'.$this->name : '';
  98.         $generation 1;
  99.         $ancestor =$this;
  100.         while ($ancestor->parentid AND $generation 3{
  101.             $ancestor =$ancestor->getParent();
  102.             $generation++;
  103.             $names '/'.$ancestor->name.$names;
  104.         }
  105.         if ($ancestor->parentid$names '..'.$names;
  106.         if ($namesreturn $names;
  107.         return '-';
  108.     }
  109.  
  110.     function &addChildren (&$descendants$published=true$search=''$recurse=false{
  111.         $children array();
  112.         $handler mosContainerHandler::getInstance();
  113.         foreach ($this->children as $i{
  114.             $container =$handler->getBasicContainer($i);
  115.             if ($published AND $container->published == 0continue;
  116.             if ($search AND strpos(strtolower($container->name)strtolower($search)) === falsecontinue;
  117.             $children[=$container;
  118.             $descendants[=$container;
  119.         }
  120.         if ($recurseforeach ($children as $child$child->addChildren ($descendants$published$search$recurse);
  121.         return $children;
  122.     }
  123.  
  124.     function &getChildren ($published=true$search=''{
  125.         $children array();
  126.         $this->addChildren($children$published$search);
  127.         return $children;
  128.     }
  129.  
  130.     function &getDescendants ($search=''{
  131.         $descendants array();
  132.         $this->addChildren ($descendantsfalse$searchtrue);
  133.         return $descendants;
  134.     }
  135.  
  136.     function &getParent ({
  137.         $handler mosContainerHandler::getInstance();
  138.         $parent =$handler->getBasicContainer($this->parentid);
  139.         return $parent;
  140.     }
  141.  
  142.     function getSelectList ($type$parm$published$notThis=0{
  143.         $selector[mosHTML::makeOption(0,T_('No parent'));
  144.         $handler mosContainerHandler::getInstance();
  145.         foreach ($handler->getCategories(as $category$category->addSelectList('',$selector,$notThis,$published);
  146.         return mosHTML::selectList$selector$type$parm'value''text'$this->id );
  147.     }
  148.  
  149.     function addSelectList ($prefix&$selector$notThis$published{
  150.         if (($notThis == 0OR ($this->id != $notThis)) $selector[mosHTML::makeOption($this->id$prefix.htmlspecialchars($this->name));
  151.         foreach ($this->getChildren($publishedas $container$container->addSelectList($prefix.$this->name.'/',$selector,$notThis,$published);
  152.     }
  153.  
  154.     function getURL ({
  155.     }
  156.  
  157.     function setPathway ({
  158.     }
  159.  
  160.     function &getIcons ({
  161.         $iconList '';
  162.         $live_site mamboCore::get('mosConfig_live_site');
  163.         $iconDir new mosDirectory (mamboCore::get('mosConfig_absolute_path').'/administrator/components/com_containers/images/folder_icons');
  164.         $files $iconDir->listAll();
  165.         $ss 0;
  166.         foreach ($files as $file{
  167.             $iconList.="\n<a href=\"JavaScript:paste_strinL('{$file}')\" onmouseover=\"window.status='{$file}'; return true\"><img src=\"{$live_site}/administrator/components/com_containers/images/folder_icons/{$file}\" width=\"32\" height=\"32\" border=\"0\" alt=\"{$file}\" /></a>&nbsp;&nbsp;";
  168.             $ss++;
  169.             if ($ss 10 == 0$iconList.="<br/>\n";
  170.         }
  171.         return $iconList;
  172.     }
  173.  
  174.  
  175.     function togglePublished ($idlist$value{
  176.         $cids implode','$idlist );
  177.         $sql "UPDATE #__downloads_containers SET published=$value""\nWHERE id IN ($cids)";
  178.         remositoryRepository::doSQL ($sql);
  179.     }
  180.  
  181.     function mosImageURL($imageName$width=32$height=32{
  182.         $live_site mamboCore::get('mosConfig_live_site');
  183.         $element '<img src="';
  184.         $element .= $live_site.'/administrator/components/com_containers/images/'.$imageName;
  185.         $element .= '" width="';
  186.         $element .= $width;
  187.         $element .= '" height="';
  188.         $element .= $height;
  189.         $element .= '" border="0" align="middle" alt="';
  190.         $element .= $imageName;
  191.         $element .= '"/>';
  192.         return $element;
  193.     }
  194.  
  195. }
  196.  
  197.     var $rows = array();
  198.     var $links = array();
  199.     var $anchor = '';
  200.  
  201.     function mosContainerHandler ({
  202.         $this->resetData();
  203.     }
  204.  
  205.     static function &getInstance ({
  206.         static $instance;
  207.         if (!is_object($instance)) $instance new mosContainerHandler();
  208.         return $instance;
  209.     }
  210.     
  211.     function resetData ({
  212.         unset ($this->rows$this->links$this->anchor);
  213.         $database mamboDatabase::getInstance();
  214.         $this->anchor =new mosContainer();
  215.         $sql 'SELECT id, parentid, name, published, ordering FROM #__containers ORDER BY ordering, name';
  216.         $this->rows =$database->doSQLget($sql'mosContainer');
  217.         foreach ($this->rows as $i=>$row$this->links[$row->id$i;
  218.         foreach ($this->rows as $rowif ($row->parentid{
  219.             $parent =$this->rows[$this->links[$row->parentid]];
  220.             $parent->addChild($row->id);
  221.         }
  222.         else $this->anchor->addChild($row->id);
  223.     }
  224.  
  225.     function &getBasicContainer ($id{
  226.         if ($id == 0return $this->anchor;
  227.         return $this->rows[$this->links[$id]];
  228.     }
  229.  
  230.     function &getContainer ($id{
  231.         global $database;
  232.         $result =$this->getBasicContainer($id);
  233.         $result->load();
  234.         return $result;
  235.     }
  236.  
  237.     function &getCategories ($published false$search null{
  238.         $categories array();
  239.         foreach ($this->anchor->getChildren(as $category{
  240.             if ($published AND $category->published == 0continue;
  241.             if ($search AND strpos(strtolower($category->name)strtolower($search)) === falsecontinue;
  242.             $categories[$category;
  243.         }
  244.         return $categories;
  245.     }
  246.  
  247.     function getDescendantIDList ($id$search=''{
  248.         $top $this->getBasicContainer ($id);
  249.         $descendants =$top->getDescendants ($search);
  250.         $list $id;
  251.         foreach ($descendants as $descendant$list .= ','.$descendant->id;
  252.         return $list;
  253.     }
  254.  
  255.     function getSelectList ($allowTop$default$type$parm&$user{
  256.         if ($allowTop$selector[mosHTML::makeOption(0,_DOWN_NO_PARENT);
  257.         foreach ($this->getCategories(as $category$category->addSelectList(''$selectornull$user);
  258.         if (isset($selector)) return mosHTML::selectList$selector$type$parm'value''text'$default );
  259.         else return '';
  260.     }
  261.  
  262.     // Only needed for testing
  263.     function displayChildren (&$container{
  264.         echo '<br />'.$container->name.' has children:<br />';
  265.         foreach ($container->children as $childecho $child->name.' whose parent is '.$child->parent->name.'<br />';
  266.         foreach ($container->children as $childdisplayChildren ($child);
  267.     }
  268.  
  269.     function markTrash ({
  270.         $database mamboDatabase::getInstance();
  271.         foreach ($this->rows as $rowif ($row->isTrash()) $trash[$row->id;
  272.         if (isset($trash)) {
  273.             $trashlist implode (','$trash);
  274.             $sql "DELETE FROM #__containers WHERE id IN ($trashlist)";
  275.             $database->doSQL($sql);
  276.         }
  277.     }
  278.  
  279. }
  280.  
  281. ?>

Documentation generated on Mon, 05 May 2008 16:18:16 +0400 by phpDocumentor 1.4.0